<template>
  <div class="gl_heightFull gl_contentBox">
    <div class="demo-input-suffix gl_searchBox">
      <el-row :gutter="20">
        <el-col :md="4" :lg="4">
          <p>审核状态</p>
          <el-select v-model="Isstate" size="mini" @change="gettablelist()">
            <el-option label="全部" value="all" />
            <el-option label="待审核" value="Pending" />
            <el-option label="审核通过" value="Approved" />
            <el-option label="审核失败" value="NotApproved" />
          </el-select>
        </el-col>
        <el-col :span="6">
          <p>提交时间</p>
          <el-date-picker
            v-model="freeDate"
            size="mini"
            style="width: 100%"
            type="daterange"
            range-separator="至"
            start-placeholder="提交开始日期"
            end-placeholder="提交结束日期"
            value-format="yyyy-MM-dd"
            @change="changeAttendance"
          />
        </el-col>
        <el-col :md="4" :lg="4">
          <p>提交机构</p>
          <el-input v-model="Api_GET_ClubDuanExamEntryApprovalQO.OrganizationUnitName" placeholder="请输入机构名称" size="mini" clearable @change="gettablelist()" />
        </el-col>
        <el-col :md="4" :lg="4">
          <el-button type="primary" style="margin-top:25px" size="mini" @click="gettablelist()">筛选</el-button>
          <el-button type="warning" size="mini" @click="reset()">{{ $t('button.Reset') }}</el-button>
        </el-col>
      </el-row>
    </div>

    <div style="margin-top:15px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column label="序号" type="index" align="center" width="55" />
        <el-table-column label="提交机构" prop="organizationUnitName" />
        <el-table-column label="提交时间" prop="name">
          <template slot-scope="{ row }">
            <span v-if="row.submissionTime">
              {{ row.submissionTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="提交人数" align="center" prop="studentCount" />
        <el-table-column label="审核状态" align="center">
          <template slot-scope="{row}">
            <span v-for="item in dict.duanExamEntryStatus" :key="item.code" class="nav_text">{{ item.code == row.approveStatusCode ? item.value : '' }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="审核结果" align="center" prop="approveRemark" /> -->
        <el-table-column label="操作" width="160">
          <template slot-scope="{ row }">
            <el-button size="mini" type="text" @click="todetail(row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubDuanExamEntryApprovalQO.Page"
        :page-size="Api_GET_ClubDuanExamEntryApprovalQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { api_GET_ClubDuanExamEntryApproval } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubDuanExamEntryApprovalQO } from '@/lib/form/hall/swaggerForm';
export default {

  data() {
    return {
      tableData: [],
      tableLoading: false,
      IsEnabled: '',
      Isstate: 'all',
      totalPage: 0,
      freeDate: [],

      Api_GET_ClubDuanExamEntryApprovalQO: new Api_GET_ClubDuanExamEntryApprovalQO() // 考试审核数据
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.getDict();
    this.gettablelist();
    this.Isstate = ['Pending', 'Approved', 'NotApproved'];
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    // 获取考试审核列表
    gettablelist(page) {
      this.tableLoading = true;
      if (this.Isstate === 'all') {
        this.Api_GET_ClubDuanExamEntryApprovalQO.ApproveStatusCodes = ['Pending', 'Approved', 'NotApproved'];
      }
      if (this.Isstate === 'Pending') {
        this.Api_GET_ClubDuanExamEntryApprovalQO.ApproveStatusCodes = ['Pending'];
      }
      if (this.Isstate === 'Approved') {
        this.Api_GET_ClubDuanExamEntryApprovalQO.ApproveStatusCodes = ['Approved'];
      }
      if (this.Isstate === 'NotApproved') {
        this.Api_GET_ClubDuanExamEntryApprovalQO.ApproveStatusCodes = ['NotApproved'];
      }
      this.Api_GET_ClubDuanExamEntryApprovalQO.IncludeDuanExamEntryStatus = true;
      this.Api_GET_ClubDuanExamEntryApprovalQO.DuanExamId = this.$route.query.id; // type: string
      // this.Api_GET_ClubDuanExamEntryApprovalQO.ApproveStatusCodes = this.Isstate;
      this.Api_GET_ClubDuanExamEntryApprovalQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubDuanExamEntryApprovalQO.Page = page || 1;
      this.Api_GET_ClubDuanExamEntryApprovalQO.SkipCount = (this.Api_GET_ClubDuanExamEntryApprovalQO.Page - 1) * this.Api_GET_ClubDuanExamEntryApprovalQO.MaxResultCount;
      api_GET_ClubDuanExamEntryApproval(this.Api_GET_ClubDuanExamEntryApprovalQO).then(res => {
        this.totalPage = res.totalCount;
        this.tableData = res.items;
        this.tableLoading = false;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    // 切换考试日期
    changeAttendance (val) {
      const _start = val ? val[0] + ' 00:00:00' : null;
      const _end = val ? val[1] + ' 23:59:59' : null;
      this.Api_GET_ClubDuanExamEntryApprovalQO.MinSubmissionTime = _start;
      this.Api_GET_ClubDuanExamEntryApprovalQO.MaxSubmissionTime = _end;
      this.gettablelist();
    },
    // 打开新增
    todetail(row) {
      console.log(row);
      if (row.approveStatusCode !== '' && row.approveStatusCode !== 'Pending') {
        this.$router.push({ name: 'Auditdetail', query: { id: this.$route.query.id, rid: row.id, disbtn: true, name: row.organizationUnitName }});
      } else {
        this.$router.push({ name: 'Auditdetail', query: { id: this.$route.query.id, rid: row.id, disbtn: false, name: row.organizationUnitName }});
      }
    },
    // 分页按钮
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubDuanExamEntryApprovalQO.MaxResultCount = MaxResultCount;
      this.gettablelist();
    },
    pageIndexChange(currentPage) {
      this.gettablelist(currentPage);
    },
    // 重置按钮
    reset () {
      this.freeDate = [];
      this.Isstate = '';
      this.Api_GET_ClubDuanExamEntryApprovalQO = new Api_GET_ClubDuanExamEntryApprovalQO();
      this.gettablelist();
    }
  }

};
</script>

<style lang="scss" scoped>

</style>
